/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.common.exception;

import com.aduib.boot.common.util.ExceptionUtils;
import com.aduib.boot.common.util.StrUtils;

/**
 * @description: IORuntimeException
 * @author: zzh
 * @date: 2021/10/28 10:18
 */
public class IoException extends RuntimeException {

  private static final long serialVersionUID = 8247610319171014183L;

  public IoException(Throwable e) {
    super(ExceptionUtils.getMessage(e), e);
  }

  public IoException(String message) {
    super(message);
  }

  public IoException(String messageTemplate, Object... params) {
    super(StrUtils.format(messageTemplate, params));
  }

  public IoException(String message, Throwable throwable) {
    super(message, throwable);
  }

  public IoException(Throwable throwable, String messageTemplate, Object... params) {
    super(StrUtils.format(messageTemplate, params), throwable);
  }

  /**
   * 导致这个异常的异常是否是指定类型的异常
   *
   * @param clazz 异常类
   * @return 是否为指定类型异常
   */
  public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
    final Throwable cause = this.getCause();
    return null != clazz && clazz.isInstance(cause);
  }
}
